package hittegods.database;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class IniReader {

    private String user;
    private String host;
    private String password;
    private String databaseName;
    private int port;

    public IniReader() {
        getFileContent();
    }

    private void getFileContent() {

        try {
            File inifile = new File("database.ini");
            Scanner scan = new Scanner(inifile);
            String input = "";
            String output = "";
            while (scan.hasNextLine()) {
                input += scan.nextLine() + "\n";
            }
            String[] strings = input.split("\n");
            for (int i = 1; i < strings.length - 1; i++) {
                String[] meh = strings[i].split("\"");
                output += meh[1] + " ";
            }
            String[] data = output.split(" ");
            user = data[0];
            password = data[1];
            host = data[2];
            databaseName = data[3];
            port = Integer.parseInt(data[4]);
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
    }

    public String getUser() {
        return user;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public String getPassword() {
        return password;
    }

    public String getDatabaseName() {
        return databaseName;
    }
}